package edu.uts.reekie.designer;

import java.io.IOException;
import java.io.InputStream;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;



public final class ImageHelper {
	
	public static <T> Image createFromResource(Class<T> sourceClass, String name) {
		
		InputStream stream = sourceClass.getResourceAsStream(name);
		Image image = new Image(null, stream);
		try {
			stream.close();
		} catch (IOException ioe) {
		}
		return image;
	}
	
	public static Image createFromFigureResource(String name) {
		return createFromResource(edu.uts.reekie.designer.figures.ConnectorLabel.class, name);
	}
	public static Image createFromModelResource(String name) {
		return createFromResource(edu.uts.reekie.designer.model.Note.class, name);	
	}
	
	public static ImageDescriptor createDescriptorFromModelResource(String name){
		return ImageDescriptor.createFromFile(edu.uts.reekie.designer.model.Note.class, name);
	}
	
	public static ImageDescriptor createDescriptorFromFigureResource(String name){
		return ImageDescriptor.createFromFile(edu.uts.reekie.designer.figures.ConnectorLabel.class, name);
	}
	
	
	public static Image createFromConceptualFigureResource(String name) {
		return createFromResource(edu.uts.reekie.designer.conceptual.figures.ViewComponentFigure.class, name);
	}
	public static Image createFromConceptualModelResource(String name) {
		return createFromResource(edu.uts.reekie.designer.conceptual.model.ViewComponent.class, name);	
	}
	public static ImageDescriptor createDescriptorFromConceptualModelResource(String name){
		return ImageDescriptor.createFromFile(edu.uts.reekie.designer.conceptual.model.ViewComponent.class, name);
	}
	
	
	
	
	
	public static Image createFromExecutionlFigureResource(String name) {
		return createFromResource(edu.uts.reekie.designer.execution.figures.ViewComponentFigure.class, name);
	}
	public static Image createFromExecutionModelResource(String name) {
		return createFromResource(edu.uts.reekie.designer.execution.model.ViewComponent.class, name);	
	}
	public static ImageDescriptor createDescriptorFromExecutionModelResource(String name){
		return ImageDescriptor.createFromFile(edu.uts.reekie.designer.execution.model.ViewComponent.class, name);
	}
	
	
	
	public static Image createFromImplementationFigureResource(String name) {
		return createFromResource(edu.uts.reekie.designer.implementation.figures.ViewComponentFigure.class, name);
	}
	public static Image createFromImplementationModelResource(String name) {
		return createFromResource(edu.uts.reekie.designer.implementation.model.ViewComponent.class, name);	
	}
	
	public static ImageDescriptor createDescriptorFromImplementationModelResource(String name){
		return ImageDescriptor.createFromFile(edu.uts.reekie.designer.implementation.model.ViewComponent.class, name);
	}
}
